package com.kuaimacode.kframework.api.service.category;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.category.AgentServMapper;
import com.kuaimacode.kframework.mybatis.models.category.AgentServ;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @date 2019/03/22
 */
@Service
public class AgentServService extends ServiceImpl<AgentServMapper, AgentServ> {

    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<AgentServ> findAll(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize,true,false,null);
    		List<AgentServ> datas = baseMapper.selectList(null);
    		return new PageInfo<AgentServ>(datas);
    	}


	/**
	 * 根据分站信息查询服务品类
	 * @param agentId
	 * @return
	 */
    	public List<AgentServ> queryServByAgentId(String agentId){
    		QueryWrapper queryWrapper = new QueryWrapper();
			queryWrapper.eq("agent_id",agentId);

			queryWrapper.eq("delete_status",Constant.DeleteStateEnum.NORMAL.getCode());

			return baseMapper.selectList(queryWrapper);

		}

		/**
		 * 根据分站信息及类型编码查询服务品类
		 * @param agentId
		 * @return
		 */
		public AgentServ queryServByAgentIdAndCode(String agentId, String type , String childType){
			QueryWrapper queryWrapper = new QueryWrapper();
			if(agentId!=null && !"".equals(agentId)){
				queryWrapper.eq("agent_id",agentId);
			} else{
				queryWrapper.eq("agent_id", Constant.DEFAULT_AGENT_ID);
			}
			queryWrapper.eq("service_code",childType);
			queryWrapper.eq("service_class",type);
			queryWrapper.eq("delete_status",Constant.DeleteStateEnum.NORMAL.getCode());
			return baseMapper.selectOne(queryWrapper);
		}
}

